package com.ea.eadp.nexus.test.pageDefinition;

import com.ea.eadp.nexus.test.common.PageOperation;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

/**
 * Created with IntelliJ IDEA.
 * User: WenjieLu
 * Date: 6/9/13
 * Time: 11:14 AM
 * To change this template use File | Settings | File Templates.
 */
public class AgeUp_PC extends BasePage {

    public AgeUp_PC(WebDriver driver) {
        super(driver, AgeUp_PC.class);
    }
    public void setEmail(String email) {
        driver.switchTo().window(this.operationWindowHandle);
        log.info(email);
        PageOperation.SendKeyToElement(driver, "email", email);
    }

    public void setSecurityQuestion(String question) throws Exception {
        driver.switchTo().window(this.operationWindowHandle);
        log.info(question);
        String cssSelector = "#clientreg_securityqa";
        PageOperation.SelectCssDropDownItem(driver, cssSelector, question);
    }

    public void setSecurityAnswer(String answer) {
        driver.switchTo().window(this.operationWindowHandle);
        log.info(answer);
        PageOperation.SendKeyToElement(driver, "securityAnswer", answer);
    }

    public void checkboxReadAccept(boolean check) {
        driver.switchTo().window(this.operationWindowHandle);
        if (check && !driver.findElement(By.id("readAccept")).isSelected()) {
            driver.findElement(By.xpath("//li[@id='read-accept-container']/div/div/span")).click();
        } else if (!check && driver.findElement(By.id("readAccept")).isSelected()) {
            driver.findElement(By.xpath("//li[@id='read-accept-container']/div/div/span")).click();
        }
    }

    public void clickContinueToPrivacySetting(){
        driver.switchTo().window(this.operationWindowHandle);
        PageOperation.WebDriverWaitByXpath(driver,"//a[@id='submit-btn']/span/span");
        driver.findElement(By.xpath("//a[@id='submit-btn']/span/span")).click();
        PageOperation.WebDriverWaitByXpath(driver,"//div[@id='panel-privacy-settings']");
    }

    public void clickContinueToCreateProfile(){
        driver.switchTo().window(this.operationWindowHandle);
        driver.findElement(By.xpath("//div[@id='panel-privacy']/div[3]/a[@id='submit-btn']/span/span")).click();
        PageOperation.WebDriverWaitByXpath(driver,"//div[@id='panel-profile-settings']");
    }

    public String getStatusForContinue(){
        driver.switchTo().window(this.operationWindowHandle);
        return driver.findElement(By.id("submit-btn")).getAttribute("class").toString();
    }

    public String getEmailError(){
        return getElementStringByXPath("//li[@id='email-container']/div[1]/span[3]");
    }

    public String getSecAnswerError(){
        return getElementStringByXPath("//li[@id='secanswer-container']/div[1]/span[3]");
    }

    public String getHeader(){
        return getElementStringByXPath("//div[@id='panel-profile']/h2");
    }

    public String getAgeUpBody(){
        return getElementStringByXPath("//div[@id='panel-profile']/p");
    }
}
